﻿#! python3
# !/usr/bin/python
# -*- coding: UTF-8 -*-
from sys import exit

import os

# 头文件类型
file_type = ["h"]

# 前缀
path_head = "${workspaceFolder}"

# 后缀
path_tail = ""

# 分隔符
path_split_ch = '\\'


dir_deep = 0

# 递归删除子函数
def search_dir(dir_in, out_ref):
    global dir_deep
    # global file_type

    # 文件名列表
    fl_list = os.listdir(dir_in)
    dir_deep += 1
    
    out_st = 0
    for i in range(len(fl_list)):
        namelist = fl_list[i].split(".")
        # 文件的路径 + 名字
        path_now = dir_in + "/" + fl_list[i]
        # 如果是文件夹，递归
        if os.path.isdir(path_now):
            search_dir(path_now, out_ref + path_split_ch + fl_list[i])
            continue
        # 获取后缀
        suffix = namelist[len(namelist) - 1]
        
        # 类型检测 
        bingo = 0
        for type_check in file_type:
            if suffix == type_check:
                bingo = 1
                break
                
        # 命中后显示路径，继续搜索子目录
        if bingo != 0 and out_st == 0:
            print(out_ref + path_tail)
            out_st = 1

    dir_deep -= 1
    return


# 获取当前路径
path_base = os.getcwd()

print("================================================================================")
# 显示搜索信息
del_list = "搜索类型::"
for type_x in file_type:
    del_list = del_list + " | ." + type_x
print("目标位置:: " + path_base + "\n")
print(del_list + "\n")

# 操作确认
#del_confirm = input("输入“OK”确认,其他取消: ")
del_confirm = "OK";
del_confirm = del_confirm.upper()
if del_confirm != "OK":
    exit(0)

# 搜索
print("================================================================================")
path_src = path_base
search_dir(path_src, path_head)
print("================================================================================")

input("Enter key to quit!")

exit(0)
